﻿using GMall.AdministrationService.Menus;
using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore.Modeling;
using Volo.Abp.Identity;

namespace GMall.AdministrationService.EntityFrameworkCore;

public static class AdministrationServiceDbContextModelCreatingExtensions
{
    public static void ConfigureAdministrationService(
        this ModelBuilder builder)
    {
        Check.NotNull(builder, nameof(builder));

        builder.Entity<Menu>(b =>
        {
            b.ToTable(AdministrationServiceDbProperties.DbTablePrefix + "Menus", AdministrationServiceDbProperties.DbSchema);

            b.ConfigureByConvention();

            b.Property(m => m.Code).IsRequired().HasMaxLength(95)
                .HasColumnName(nameof(Menu.Code));
            b.Property(m => m.DisplayName).IsRequired().HasMaxLength(128)
                .HasColumnName(nameof(Menu.DisplayName));

            //b.HasMany<Menu>().WithOne().HasForeignKey(m => m.ParentId);

            b.HasIndex(m => m.Code);

            b.ApplyObjectExtensionMappings();
        });
    }
}
